Skip to content

Commit 14713b5

Browse files
committed
Get basic chatbot web gui working in llamafiler
1 parent 40e92cf commit 14713b5

23 files changed

+674
-258
lines changed

llamafile/flags.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llamafile.h"
2121
#include "trust.h"
2222

23+
#include <cosmo.h>
2324
#include <errno.h>
2425
#include <fcntl.h>
2526
#include <limits.h>
@@ -49,7 +50,8 @@ const char *FLAG_ip_header = nullptr;
4950
const char *FLAG_listen = "0.0.0.0:8080";
5051
const char *FLAG_model = nullptr;
5152
const char *FLAG_prompt = nullptr;
52-
const char *FLAG_url_prefix = nullptr;
53+
const char *FLAG_url_prefix = "";
54+
const char *FLAG_www_root = "/zip/www";
5355
double FLAG_token_rate = 1;
5456
float FLAG_temp = 0.8;
5557
int FLAG_batch = 2048;
@@ -140,13 +142,6 @@ void llamafile_get_flags(int argc, char **argv) {
140142
continue;
141143
}
142144

143-
if (!strcmp(flag, "--url-prefix")) {
144-
if (i == argc)
145-
missing("--url-prefix");
146-
FLAG_url_prefix = argv[i++];
147-
continue;
148-
}
149-
150145
if (!strcmp(flag, "-k") || !strcmp(flag, "--keepalive")) {
151146
if (i == argc)
152147
missing("--keepalive");
@@ -219,6 +214,28 @@ void llamafile_get_flags(int argc, char **argv) {
219214
//////////////////////////////////////////////////////////////////////
220215
// http server flags
221216

217+
if (!strcmp(flag, "--www-root")) {
218+
if (i == argc)
219+
missing("--www-root");
220+
FLAG_www_root = argv[i++];
221+
continue;
222+
}
223+
224+
if (!strcmp(flag, "--url-prefix")) {
225+
if (i == argc)
226+
missing("--url-prefix");
227+
FLAG_url_prefix = argv[i++];
228+
if (!IsAcceptablePath(FLAG_url_prefix, -1)) {
229+
tinyprint(2, "error: --url-prefix must not have // or /. or /./ or /../\n", NULL);
230+
exit(1);
231+
}
232+
if (endswith(FLAG_url_prefix, "/")) {
233+
tinyprint(2, "error: --url-prefix must not be slash or end with slash\n", NULL);
234+
exit(1);
235+
}
236+
continue;
237+
}
238+
222239
if (!strcmp(flag, "--http-ibuf-size")) {
223240
if (i == argc)
224241
missing("--http-ibuf-size");

llamafile/llamafile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern const char *FLAG_listen;
2626
extern const char *FLAG_model;
2727
extern const char *FLAG_prompt;
2828
extern const char *FLAG_url_prefix;
29+
extern const char *FLAG_www_root;
2930
extern double FLAG_token_rate;
3031
extern float FLAG_temp;
3132
extern int FLAG_batch;

llamafile/server/BUILD.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ LLAMAFILE_SERVER_HDRS = $(filter %.h,$(LLAMAFILE_SERVER_FILES))
88
LLAMAFILE_SERVER_INCS = $(filter %.inc,$(LLAMAFILE_SERVER_FILES))
99
LLAMAFILE_SERVER_SRCS = $(filter %.cpp,$(LLAMAFILE_SERVER_FILES))
1010
LLAMAFILE_SERVER_OBJS = $(LLAMAFILE_SERVER_SRCS:%.cpp=o/$(MODE)/%.o)
11+
LLAMAFILE_SERVER_ASSETS = $(wildcard llamafile/server/www/*)
1112

1213
$(LLAMAFILE_SERVER_OBJS): private CCFLAGS += -g
1314

@@ -22,6 +23,11 @@ o/$(MODE)/llamafile/server/main: \
2223
o/$(MODE)/llama.cpp/llava/llava.a \
2324
o/$(MODE)/double-conversion/double-conversion.a \
2425
o/$(MODE)/stb/stb.a \
26+
$(LLAMAFILE_SERVER_ASSETS:%=o/$(MODE)/%.zip.o)
27+
28+
# turn /zip/llamafile/server/www/...
29+
# into /zip/www/...
30+
$(LLAMAFILE_SERVER_ASSETS:%=o/$(MODE)/%.zip.o): private ZIPOBJ_FLAGS += -C2
2531

2632
$(LLAMAFILE_SERVER_OBJS): llamafile/server/BUILD.mk
2733

llamafile/server/cleanup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@
1717

1818
#include "cleanup.h"
1919

20+
#include <unistd.h>
2021
#include <vector>
2122

2223
#include "llama.cpp/llama.h"
2324

25+
void
26+
cleanup_fildes(void* arg)
27+
{
28+
close((intptr_t)arg);
29+
}
30+
2431
void
2532
cleanup_float_vector(void* arg)
2633
{

llamafile/server/cleanup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#pragma once
1919

20+
void
21+
cleanup_fildes(void*);
22+
2023
void
2124
cleanup_float_vector(void*);
2225

0 commit comments

Comments
 (0)